import 'package:get_it/get_it.dart';
import 'package:mobile_app.core/injection_container.dart' as core_di;
import 'package:mobile_app.home.collections/single_lexical_item_page/domain/helpers/create_deletion_card_action_if_reasonable/helper.dart';
import 'package:mobile_app.home.collections/single_lexical_item_page/domain/helpers/get_card_actions/helper.dart';
import 'package:mobile_app.home.collections/single_lexical_item_page/domain/helpers/is_custom_lexical_item_used_in_any_collection/helper.dart';
import 'package:mobile_app.home.collections/single_lexical_item_page/domain/use_cases/add_lexical_item_to_custom_collection/use_case.dart';
import 'package:mobile_app.home.collections/single_lexical_item_page/domain/use_cases/add_lexical_item_to_learning_queue/use_case.dart';
import 'package:mobile_app.home.collections/single_lexical_item_page/domain/use_cases/complete_custom_lexical_item_deletion/use_case.dart';
import 'package:mobile_app.home.collections/single_lexical_item_page/domain/use_cases/exclude_lexical_item_from_learning/use_case.dart';
import 'package:mobile_app.home.collections/single_lexical_item_page/domain/use_cases/get_initial_data/use_case.dart';
import 'package:mobile_app.home.collections/single_lexical_item_page/domain/use_cases/handle_available_email_app_outer_update/use_case.dart';
import 'package:mobile_app.home.collections/single_lexical_item_page/domain/use_cases/handle_cached_image_path_map_outer_update/use_case.dart';
import 'package:mobile_app.home.collections/single_lexical_item_page/domain/use_cases/handle_dialect_outer_update/use_case.dart';
import 'package:mobile_app.home.collections/single_lexical_item_page/domain/use_cases/handle_image_settings_outer_update/use_case.dart';
import 'package:mobile_app.home.collections/single_lexical_item_page/domain/use_cases/handle_learning_content_outer_update/use_case.dart';
import 'package:mobile_app.home.collections/single_lexical_item_page/domain/use_cases/handle_premium_access_status_outer_update/use_case.dart';
import 'package:mobile_app.home.collections/single_lexical_item_page/domain/use_cases/initialize/use_case.dart';
import 'package:mobile_app.home.collections/single_lexical_item_page/domain/use_cases/mark_lexical_item_as_completely_learned/use_case.dart';
import 'package:mobile_app.home.collections/single_lexical_item_page/domain/use_cases/mark_lexical_item_as_known/use_case.dart';
import 'package:mobile_app.home.collections/single_lexical_item_page/domain/use_cases/pronounce_lexical_item/use_case.dart';
import 'package:mobile_app.home.collections/single_lexical_item_page/domain/use_cases/pronounce_lexical_item_use_case/use_case.dart';
import 'package:mobile_app.home.collections/single_lexical_item_page/domain/use_cases/remove_lexical_item_from_learning_queue/use_case.dart';
import 'package:mobile_app.home.collections/single_lexical_item_page/domain/use_cases/report_lexical_item_mistake_by_email/use_case.dart';
import 'package:mobile_app.home.collections/single_lexical_item_page/domain/use_cases/reset_lexical_item_progress/use_case.dart';
import 'package:mobile_app.home.collections/single_lexical_item_page/domain/use_cases/return_lexical_item_to_learning/use_case.dart';
import 'package:mobile_app.home.collections/single_lexical_item_page/domain/use_cases/start_custom_lexical_item_deletion/use_case.dart';
import 'package:mobile_app.home.core/injection_container.dart' as home_core_di;

final sl = GetIt.asNewInstance();

Future<void> init() async {
  // domain helpers

  sl.registerLazySingleton<CreateDeletionCardActionIfReasonable>(() {
    return const CreateDeletionCardActionIfReasonableImpl();
  });

  sl.registerLazySingleton<GetCardActions>(() {
    return GetCardActionsImpl(
      createAdditionToCustomCollectionCardActionIfReasonable: home_core_di.sl(),
      createAdditionToLearningQueueCardActionIfReasonable: home_core_di.sl(),
      createEditingCardActionIfReasonable: home_core_di.sl(),
      createExclusionFromLearningCardActionIfReasonable: home_core_di.sl(),
      createMarkAsCompletelyLearnedCardActionIfReasonable: home_core_di.sl(),
      createMarkAsKnownCardActionIfReasonable: home_core_di.sl(),
      createMistakeReportCardActionIfReasonable: home_core_di.sl(),
      createProgressResetCardActionIfReasonable: home_core_di.sl(),
      createDeletionCardActionIfReasonable: sl(),
      createRemovalFromLearningQueueCardActionIfReasonable: home_core_di.sl(),
      createReturnToLearningCardActionIfReasonable: home_core_di.sl(),
      getPermittedCollectionListItemIds: home_core_di.sl(),
      getPermittedLexicalItemIds: home_core_di.sl(),
    );
  });

  sl.registerLazySingleton<IsCustomLexicalItemUsedInAnyCollection>(() {
    return const IsCustomLexicalItemUsedInAnyCollectionImpl();
  });

  // use cases

  sl.registerLazySingleton<AddLexicalItemToCustomCollection>(() {
    return AddLexicalItemToCustomCollectionImpl(
      learningContentRepository: core_di.sl(),
      applyCollectionListItemUpdate: home_core_di.sl(),
      applyLexicalItemAdditionToCustomCollection: home_core_di.sl(),
      getCardActions: sl(),
    );
  });

  sl.registerLazySingleton<AddLexicalItemToLearningQueue>(() {
    return AddLexicalItemToLearningQueueImpl(
      learningContentRepository: core_di.sl(),
      getCardActions: sl(),
      applyLexicalItemAdditionToLearningQueue: home_core_di.sl(),
      applyLexicalItemUpdate: home_core_di.sl(),
    );
  });

  sl.registerLazySingleton<CompleteCustomLexicalItemDeletion>(() {
    return CompleteCustomLexicalItemDeletionImpl(
      learningContentRepository: core_di.sl(),
      applyAllCollectionListItemNonexistentLexicalItemRemoval: home_core_di.sl(),
    );
  });

  sl.registerLazySingleton<ExcludeLexicalItemFromLearning>(() {
    return ExcludeLexicalItemFromLearningImpl(
      learningContentRepository: core_di.sl(),
      getCardActions: sl(),
      applyLexicalItemExclusionFromLearning: home_core_di.sl(),
      applyLexicalItemUpdate: home_core_di.sl(),
    );
  });

  sl.registerLazySingleton<GetInitialData>(() {
    return GetInitialDataImpl(
      getCardActions: sl(),
      imageService: core_di.sl(),
      getLexicalItemEffectiveImagePath: home_core_di.sl(),
    );
  });

  sl.registerLazySingleton<HandleAvailableEmailAppOuterUpdate>(() {
    return HandleAvailableEmailAppOuterUpdateImpl(
      getCardActions: sl(),
    );
  });

  sl.registerLazySingleton<HandleCachedImagePathMapOuterUpdate>(() {
    return HandleCachedImagePathMapOuterUpdateImpl(
      getLexicalItemEffectiveImagePath: home_core_di.sl(),
    );
  });

  sl.registerLazySingleton<HandleDialectOuterUpdate>(() {
    return HandleDialectOuterUpdateImpl(
      isLexicalItemSafeToPronounce: home_core_di.sl(),
    );
  });

  sl.registerLazySingleton<HandleImageSettingsOuterUpdate>(() {
    return HandleImageSettingsOuterUpdateImpl(
      imageService: core_di.sl(),
      getLexicalItemEffectiveImagePath: home_core_di.sl(),
    );
  });

  sl.registerLazySingleton<HandleLearningContentOuterUpdate>(() {
    return HandleLearningContentOuterUpdateImpl(
      getCardActions: sl(),
      isLexicalItemSafeToPronounce: home_core_di.sl(),
    );
  });

  sl.registerLazySingleton<HandlePremiumAccessStatusOuterUpdate>(() {
    return HandlePremiumAccessStatusOuterUpdateImpl(
      getCardActions: sl(),
    );
  });

  sl.registerLazySingleton<Initialize>(() {
    return InitializeImpl(
      imageService: core_di.sl(),
      maybeStartLexicalItemImageDownload: home_core_di.sl(),
    );
  });

  sl.registerLazySingleton<MarkLexicalItemAsCompletelyLearned>(() {
    return MarkLexicalItemAsCompletelyLearnedImpl(
      learningContentRepository: core_di.sl(),
      getCardActions: sl(),
      applyLexicalItemMarkAsCompletelyLearned: home_core_di.sl(),
      applyLexicalItemUpdate: home_core_di.sl(),
    );
  });

  sl.registerLazySingleton<MarkLexicalItemAsKnown>(() {
    return MarkLexicalItemAsKnownImpl(
      learningContentRepository: core_di.sl(),
      getCardActions: sl(),
      applyLexicalItemMarkAsKnown: home_core_di.sl(),
      applyLexicalItemUpdate: home_core_di.sl(),
    );
  });

  sl.registerLazySingleton<PronounceLexicalItem>(() {
    return PronounceLexicalItemImpl(
      ttsService: core_di.sl(),
    );
  });

  sl.registerLazySingleton<PronounceLexicalItemUseCase>(() {
    return PronounceLexicalItemUseCaseImpl(
      ttsService: core_di.sl(),
      getLexicalItemUseCaseExample: home_core_di.sl(),
    );
  });

  sl.registerLazySingleton<RemoveLexicalItemFromLearningQueue>(() {
    return RemoveLexicalItemFromLearningQueueImpl(
      learningContentRepository: core_di.sl(),
      getCardActions: sl(),
      applyLexicalItemRemovalFromLearningQueue: home_core_di.sl(),
      applyLexicalItemUpdate: home_core_di.sl(),
    );
  });

  sl.registerLazySingleton<ReportLexicalItemMistakeByEmail>(() {
    return ReportLexicalItemMistakeByEmailImpl(
      emailService: core_di.sl(),
      getLexicalItemMistakeReportEmailBody: home_core_di.sl(),
    );
  });

  sl.registerLazySingleton<ResetLexicalItemProgress>(() {
    return ResetLexicalItemProgressImpl(
      learningContentRepository: core_di.sl(),
      getCardActions: sl(),
      applyLexicalItemProgressReset: home_core_di.sl(),
      applyLexicalItemUpdate: home_core_di.sl(),
    );
  });

  sl.registerLazySingleton<ReturnLexicalItemToLearning>(() {
    return ReturnLexicalItemToLearningImpl(
      learningContentRepository: core_di.sl(),
      getCardActions: sl(),
      applyLexicalItemReturnToLearning: home_core_di.sl(),
      applyLexicalItemUpdate: home_core_di.sl(),
    );
  });

  sl.registerLazySingleton<StartCustomLexicalItemDeletion>(() {
    return StartCustomLexicalItemDeletionImpl(
      isCustomLexicalItemUsedInAnyCollection: sl(),
    );
  });
}
